package com.baizhiedu.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Mybatis开发步骤
 *  1.实体
 *  2.实体别名
 *  3.表
 *  4.创建DAO接口
 *  5.实现Mapper文件
 *  6.注册Mapper文件
 *  7.MybatisAPI调用
 */
public class TestMybatis {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession session = sqlSessionFactory.openSession();
        UserDAO userDAO = session.getMapper(UserDAO.class);

        User user = new User();
        user.setName("suns");
        user.setPassword("123456");
        userDAO.save(user);

        session.commit();
    }
}
